
var serverurl='http://zm.runfkj.com';
var token='runfEngkj2017sesAmeParadIse168';
var uppicurl=serverurl+'/appServiceUser/uploadimg.action';
var login=serverurl+'/appServiceUser/login.action';//登录
var fogetpwd=serverurl+'/appServiceUser/forgotloginpwd.action';//忘记密码
var getyzm=serverurl+'/appServiceUser/getcode.action';//获取短信，验证码
var xiugaiurl=serverurl+'/appServiceUser/updateinfo.action';//修改个人消息
var headpic = serverurl + '/appServiceUser/uploadimg.action';//个人信息上传头像
var info = serverurl + '/appServiceUser/userinfo.action';//个人信息
var smurl=serverurl+'/appServiceUser/certification.action';//实名认证
var newsurl=serverurl+'/appServiceNtf/notifylist.action ';//消息列表
var duihuan_listurl=serverurl+'/appServiceGoods/goodslist.action';//兑换商品
var duihuanurl=serverurl+'/appServiceGoods/cash.action';//兑换
var type3=serverurl+'/appServiceTrade/replyinvate.action';//消息type3
var type2=serverurl+'/appServiceFri/replyinvate.action';//消息type2
//var type5=serverurl+'/appServiceOrd/replyordtrade.action';//消息type5
 var type4=serverurl+'/appServiceTrade/replytrade.action'//type4
var type6=serverurl+'/appServiceOrd/replyordinvate.action';//消息type6
var typeno=serverurl+'/appServiceNtf/surenotify.action';//消息，点击按钮不做请求
var type7=serverurl+'/appServiceOrd/replyordtrade.action';//消息type7
var guanjiaurl=serverurl+'/appServiceUser/usebutler.action';//管家
var exit=serverurl+'/appServiceUser/exit.action';//退出
//
var fruitlist=serverurl+'/appServiceFruit/fruitlist.action';//果实列表
var sign = serverurl + '/appServiceUser/sign.action';//签到接口
var words = serverurl + '/appServiceMsg/leavemessage.action';//留言接口
var friendlist = serverurl + '/appServiceFri/friendlist.action';//好友列表
var store = serverurl + '/appServiceFruit/warehousefruits.action';//仓库果子列表
var search = serverurl + '/appServiceUser/searchuser.action';//搜索
var sell = serverurl + '/ appServiceFruit /sell.action';//售卖果子
var count = serverurl + '/appServiceFruit/incomelog.action';//仓库果子数量
var tongji = serverurl + '/appServiceFruit/incomestatistic.action';//收益统计
var jiaoyi = serverurl + '/appServiceTrade/sendtrade.action';//发送交易
var searchFriend = serverurl + '/appServiceFri/addfriend.action';//搜索好友
var guadan = serverurl + '/appServiceOrd/sendorder.action';//挂单
var zhongzhi = serverurl + '/appServiceFruit/plant.action';//种植
var zhiwulist = serverurl + '/appServiceFruit/landfruitlist.action';//植物列表
var comfirmbuy = serverurl + '/appServiceOrd/replyordinvate.action';//对方确认/取消交易（挂单）
var guadanlist = serverurl + '/appServiceOrd/orderlist.action';//挂单列表
var addfriend = serverurl + '/appServiceFri/addfriend.action';//添加好友
var getcode = serverurl + '/appServiceUser/getcode.action';//获取验证码
var invate = serverurl + '/appServiceFri/invatefriend.action';//邀请好友
var myzhiwu = serverurl + '/appServiceFruit/fruitdetail.action';//我的植物列表
var collect=serverurl+'/appServiceFruit/collect.action';//收集植物
var kuojian=serverurl+'/appServiceFruit/extension.action';//扩建
var stealurl=serverurl+'/appServiceFri/steal.action';//偷取
var gain=serverurl+'/appServiceFri/collect.action' ;//收取
var cancelorder=serverurl+'/appServiceOrd/cancelorder.action';//取消挂单

//随机字符串
function nonce(len) {
len = len || 32;
	var $chars = 'ABCDEFGHIJKMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789';
	var maxPos = $chars.length;
	var pwd = '';
	for (i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
	}
	return pwd;
}
//生成签名
function signature(timestamp,nonce){
    var arr = [];
    arr[arr.length] = token;
    arr[arr.length] = timestamp;
    arr[arr.length] = nonce;
    arr.sort();
    var x = "";
    for (var i = 0; i < arr.length; i++) {
        x += arr[i];
    }
    var signature = hex_sha1(x);
    return signature;
}
//ajax
window.getData = function(param,callback){
    param.data.timestamp=new Date().getTime();
    param.data.nonce =nonce(10);
    param.data.signature =signature(param.data.timestamp,param.data.nonce);
    $.ajax({
        type : param.type || 'POST',
        url : param.url,
        data : param.data,
        cache :param.cache || false,
        dataType : 'json',
        success : function(data){
            if(data.errorCode){
                alert('错误'+data.errorCode)
            }
            callback&&callback(data)
        }
    })
}

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
//滑动时避免触发touch事件
function stopTouchendPropagationAfterScroll(){
    var flag = false;
    window.addEventListener('touchmove', function(ev){
        flag || (flag = true, window.addEventListener('touchend', stopTouchendPropagation, true));
    }, false);
    function stopTouchendPropagation(ev){
        ev.stopPropagation();
        setTimeout(function(){
            window.removeEventListener('touchend', stopTouchendPropagation, true);
            flag = false;
        }, 50);
    }
}

var cordovaPlugin = {
    stopMusic: function (success, fail, value) {
        return  cordova.exec(function (args) {
            success(args);
        }, function (args) {
            fail(args);
        }, 'ZmkyCordovaPlugin', 'stopMusic', [value]);
    },
    exit: function () {
        return  cordova.exec(function (args) {
        }, function (args) {
        }, 'ZmkyCordovaPlugin', 'exit', []);
    }
}
